<?php
namespace App\Repositories;

use App\Model\MaterialAssign;
use App\Traits\SingletonTrait;

class MaterialAssignRepository extends AbstractRepository
{
    use SingletonTrait;

    public function model()
    {
        return 'App\\Model\\MaterialAssign';
    }

    public function getReportFrom($assign_id){
        $assign = MaterialAssignRepository::getInstance()->getById($assign_id);
        $return=null;
        switch ($assign->type){
            case MaterialAssign::TYPE_ONE:
                $return = AreaRepository::getInstance()->one(['id','name'],[[
                    'field' => 'id',
                    'value' => $assign->data_id
                ]]);
                break;
            case MaterialAssign::TYPE_TWO:
                $return = StreetRepository::getInstance()->one(['id','name'],[[
                    'field' => 'id',
                    'value' => $assign->data_id
                ]]);
                break;
            case MaterialAssign::TYPE_THREE:
                $return = CommunityRepository::getInstance()->one(['id','name'],[[
                    'field' => 'id',
                    'value' => $assign->data_id
                ]]);
                break;
        }
        return $return;
    }
}